package com.fx.ruankao.utils;

import java.util.Date;

/**
 * 统一响应结果类
 */
public class Result {
    private int code;              // 响应状态码
    private String message;        // 响应消息
    private Object data;           // 响应数据
    private long timestamp;        // 响应时间戳

    private Result(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.timestamp = new Date().getTime();
    }

    public static Result success(Object data) {
        return new Result(200, "success", data);
    }

    public static Result success(Object data, String message) {
        return new Result(200, message, data);
    }

    public static Result success(String message) {
        return new Result(200, message, null);
    }

    public static Result error(String message) {
        return new Result(500, message, null);
    }

    public static Result error(int code, String message) {
        return new Result(code, message, null);
    }

    // getter和setter
    public int getCode() { return code; }
    public void setCode(int code) { this.code = code; }
    public String getMessage() { return message; }
    public void setMessage(String message) { this.message = message; }
    public Object getData() { return data; }
    public void setData(Object data) { this.data = data; }
    public long getTimestamp() { return timestamp; }
    public void setTimestamp(long timestamp) { this.timestamp = timestamp; }
}